{extend name="base" /}
{block name="header"}
<div class="admin_header_{$skin_name|default='default'} clearfix">
    <div class="title"><i></i>{$title|default=""}</div>
    <div class="action">
        <b></b>
        <div class="layui-btn-group layui-btn-group-only">
            <a class="layui-btn  layui-btn-disabled layui-btn-sm "><i class="fa fa-reply"></i> 返 回 </a>
        </div>
    </div>
</div>
{/block}
{block name="main"}

<div class="layui-btn-group">
    <a href="{:url('admin/auth_rule/add')}" class="layui-btn layui-btn-primary"><i class="layui-icon" style="color: #ffffff;">&#xe608;</i>添加新规则</a>
</div>

    <table class="layui-table" lay-even="" lay-skin="row" lay-size="sm">
    <colgroup>
        <col width="50">
        <col width="50">
        <col width="200">
        <col width="200">
        <col width="100">
        <col width="100">
        <col width="100">
        <col width="150">
    </colgroup>
    <thead>
    <tr>
        <th>排序</th>
        <th>编号</th>
        <th>名称</th>
        <th>规则</th>
        <th>备注</th>
        <th>类型</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <form class="layui-form" id="admin">
        {volist name="menus" id="vo"}
        <tr>
            <td><input type="text" name="orders[]" value="{$vo.orders}" style="width: 20px;" class="orders"><input type="hidden" name="id[]" value="{$vo.id}"></td>
            <td>{$vo.id}</td>
            <td><span style="font-weight:500;">{$vo.str|raw}</span>{$vo.title}</td>
            <td>{$vo.name}</td>
            <td>{$vo.description}</td>
            <td>{eq name="$vo.type" value="1"}权限节点{else /}普通节点{/eq}</td>
            <td>{eq name="$vo.status" value="1"}显示在左侧菜单{else /}只做为操作节点{/eq}</td>
            <td class="operation-menu skin">
                <a href="{:url('admin/auth_rule/edit',['id'=>$vo.id])}" class="layui-btn and-bg-{$skin_name|default='default'} layui-btn-xs a_menu"><i class="layui-icon"></i></a>
                <a href="{:url('admin/auth_rule/add',['pid'=>$vo.id])}" class="layui-btn and-bg-{$skin_name|default='default'} layui-btn-xs a_menu"><i class="layui-icon"></i></a>
                <a href="javascript:;" class="layui-btn and-bg-{$skin_name|default='default'} layui-btn-xs delete" id="{$vo.id}"><i class="layui-icon"></i></a>
            </td>
        </tr>
        {/volist}
    </form>
    </tbody>
</table>

<button class="layui-btn layui-btn-sm and-bg-{$skin_name}" lay-submit lay-filter="admin">更新排序</button>

{/block}

{block name="script"}
<script type="text/javascript">
    $('.delete').click(function(){
        var id = $(this).attr('id');
        layer.confirm('确定要删除?', function(index) {
            $.ajax({
                url:"{:url('admin/auth_rule/delete')}",
                data:{id:id},
                success:function(res) {
                    layer.msg(res.msg);
                    if(res.code == 1) {
                        setTimeout(function(){
                            location.href = res.url;
                        },1500)
                    }
                }
            })
        })
    })
</script>
<script type="text/javascript">
    $('.a_menu').click(function(){
        var url = $(this).attr('href');
        var id = $(this).attr('id');
        var a = true;
        if(id) {
            $.ajax({
                url:url
                ,async:false
                ,data:{id:id}
                ,success:function(res){
                    if(res.code == 0) {
                        layer.msg(res.msg);
                        a = false;
                    }
                }
            })
        } else {
            $.ajax({
                url:url
                ,async:false
                ,success:function(res){
                    if(res.code == 0) {
                        layer.msg(res.msg);
                        a = false;
                    }
                }
            })
        }
        return a;
    })
</script>

<script>
    layui.use(['layer', 'form'], function() {
        var layer = layui.layer,
                $ = layui.jquery,
                form = layui.form;
        form.on('submit(admin)', function(data) {
            $.ajax({
                url:"{:url('admin/auth_rule/orders')}",
                data:$('#admin').serialize(),
                type:'post',
                async: false,
                success:function(res) {
                    if(res.code == 1) {
                        layer.alert(res.msg, function(index){
                            location.href = res.url;
                        })
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
{/block}